package org.footballmanager.pandafootball.system.controller.hy;

import org.footballmanager.pandafootball.common.constants.Constants;
import org.footballmanager.pandafootball.system.controller.BaseController;
import org.footballmanager.pandafootball.system.domain.enums.JNFL;
import org.footballmanager.pandafootball.system.form.impl.FootPersonSearchForm;
import org.footballmanager.pandafootball.system.service.FootPersonService;
import org.footballmanager.pandafootball.system.service.FootTableTitleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
@SessionAttributes("footPersonSearchForm")
@RequestMapping("/hy/footPerson")
public class HyPersonController extends BaseController {
	/* 实体名称 */
	private static final String ENTITYNAME = "footPerson";
	private static final String LISTPAGE = String.format(Constants.LISTPAGE, Constants.HY, ENTITYNAME);
	private static final String VIEWPAGE = String.format(Constants.VIEWPAGE, Constants.HY, ENTITYNAME);

	@Autowired
	private FootPersonService footPersonService;
	@Autowired
	private FootTableTitleService footTableTitleService;

	/**
	 * 初始化
	 * @param map 参数
	 * @param footPersonSearchForm 条件参数
	 */
	@ModelAttribute
	public void init(Model map, @ModelAttribute FootPersonSearchForm footPersonSearchForm){
        footPersonService.init(ENTITYNAME, footPersonSearchForm, map);
	}

	@RequestMapping(value="/search")
	public String search(Model map, @ModelAttribute FootPersonSearchForm footPersonSearchForm) {
        footPersonService.search(ENTITYNAME, map, footPersonSearchForm);
        return LISTPAGE;
	}

	@RequestMapping(value = "/view", method = RequestMethod.POST)
	public String openViewPage(Model map, @RequestParam Long id,
				@ModelAttribute FootPersonSearchForm footPersonSearchForm) {
		map.addAttribute(ENTITYNAME, footPersonService.get(id));
		map.addAttribute(String.format(Constants.FORMNAME, ENTITYNAME), footPersonSearchForm);
        map.addAttribute("basicSkills", footTableTitleService.findByTableNameAndJnfl(Constants.PERSONTABLE, JNFL.BASIC));
        map.addAttribute("linkageSkills", footTableTitleService.findByTableNameAndJnfl(Constants.PERSONTABLE, JNFL.LINKAGE));
		return VIEWPAGE;
	}	
	
}
